From cdbd09f0abd3f2a861b19389964800877f1caeec Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 20 Nov 2022 13:38:58 -0700 Subject: [PATCH] fix rounding in holux. and fiddle with the make short default name so we can do a roundtrip test. --- holux.cc | 40 +++++++++++++++++++++------------------- testo.d/holux.test | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/holux.cc b/holux.cc index 0fed1e655..4d3c4ab81 100644 --- a/holux.cc +++ b/holux.cc @@ -25,15 +25,25 @@ History: */ /* This module is for the holux (gm-100) .wpo format */ -#include "defs.h" +#include // for strncpy, memset, strcpy, strlen +#include // for sprintf +#include // for gmtime, mktime, time_t, tm + +#include // for QDate +#include // for QString +#include // for QTime +#include // for qRound + +#include "defs.h" // for Waypoint, le_write16, le_write32 #include "holux.h" -//#include -#include -#include +#include "gbfile.h" // for gbfclose, gbfopen_le, gbfile, gbfread +#include "src/core/datetime.h" // for DateTime -static gbfile* file_in, *file_out; -static unsigned char* HxWFile; -static short_handle mkshort_handle; + +static gbfile* file_in; +static gbfile* file_out; +static unsigned char* HxWFile; +static short_handle mkshort_handle; #define MYNAME "Holux" @@ -149,7 +159,7 @@ static void data_read() static const char* mknshort(const char* stIn,unsigned int sLen) { -#define MAX_STRINGLEN 255 + constexpr int MAX_STRINGLEN = 255; static char strOut[MAX_STRINGLEN]; char strTmp[MAX_STRINGLEN]; @@ -163,6 +173,7 @@ static const char* mknshort(const char* stIn,unsigned int sLen) setshort_length(mkshort_handle, sLen); setshort_mustuniq(mkshort_handle, 0); + setshort_defname(mkshort_handle, ""); char* shortstr = mkshort(mkshort_handle, stIn, false); strcpy(strTmp,shortstr); @@ -181,15 +192,6 @@ static void holux_disp(const Waypoint* wpt) double lon = wpt->longitude * 36000.0; double lat = wpt->latitude * -36000.0; - - /* round it to increase the accuracy */ - if (lon != 0) { - lon += (double)((int)lon/abs((int)lon)) * .5; - } - if (lat != 0) { - lat += (double)((int)lat/abs((int)lat)) * .5; - } - short sIndex = le_read16(&((WPTHDR*)HxWFile)->num); if (sIndex >= MAXWPT) { @@ -237,8 +239,8 @@ static void holux_disp(const Waypoint* wpt) // yield undefined results for negative values. // We intentionally convert to int, then do an implicit // conversion to unsigned in the call. - le_write32(&pWptHxTmp->pt.iLatitude,(signed int) lat); - le_write32(&pWptHxTmp->pt.iLongitude,(signed int) lon); + le_write32(&pWptHxTmp->pt.iLatitude, qRound(lat)); + le_write32(&pWptHxTmp->pt.iLongitude, qRound(lon)); pWptHxTmp->checked = 01; pWptHxTmp->vocidx = (short)0xffff; le_write16(&((WPTHDR*)HxWFile)->num, ++sIndex); diff --git a/testo.d/holux.test b/testo.d/holux.test index 61e462791..4b30d1687 100644 --- a/testo.d/holux.test +++ b/testo.d/holux.test @@ -5,4 +5,4 @@ # So we verify that we can read the reference and write it and get an # identical reference. gpsbabel -i holux -f ${REFERENCE}/paris.wpo -o holux -F ${TMPDIR}/paris.wpo -# compare ${REFERENCE}/paris.wpo ${TMPDIR}/paris.wpo +bincompare ${REFERENCE}/paris.wpo ${TMPDIR}/paris.wpo -- 2.30.2